import { LoginFormValues } from '@/types/data'
import { RootThunkAction } from '../../types/store'
import { getCodeApi, loginApi } from '@/api/user'
import { setToken } from '@/utils/storage'

export const login = (values: LoginFormValues): RootThunkAction => {
  return async (dispatch) => {
    const res = await loginApi(values)
    console.log(res)
    dispatch({
      type: 'login/login',
      payload: res.data.data,
    })
    setToken(res.data.data)
  }
}

export const getCode = (mobile: string) => {
  return async() => {
    console.log('发送验码', mobile)
    await  getCodeApi(mobile)
  }
}
